package com.zls.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zls.mapper.TDeviceMapper;
import com.zls.mapper.TDeviceTypeMapper;
import com.zls.page.PageResult;
import com.zls.page.QueryPageBean;
import com.zls.pojo.TDevice;
import com.zls.pojo.TDeviceType;
import com.zls.service.TDeviceService;
import com.zls.service.TDeviceTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;

@Service
public class TDeviceTypeServiceImpl extends ServiceImpl<TDeviceTypeMapper, TDeviceType> implements TDeviceTypeService {
    @Autowired
    private TDeviceTypeMapper tDeviceTypeMapper;

    @Override
    public PageResult findPage(QueryPageBean queryPageBean) {
        PageResult pageResult = new PageResult();
        Integer currentPage = queryPageBean.getCurrentPage();//当前页
        Integer pageSize = queryPageBean.getPageSize();//每页大小
        String queryString = queryPageBean.getQueryString();//查询条件
        //total总记录数
        List<TDeviceType> page = tDeviceTypeMapper.findPage((currentPage - 1) * pageSize, pageSize,queryString);
        //rows  当前页的数据
        Long count = tDeviceTypeMapper.count(queryString);
        pageResult.setRows(page);
        pageResult.setTotal(count);
        return pageResult;
    }

    @Override
    @Transactional
    public int addType(TDeviceType tDeviceType) {
        tDeviceType.setCreateTime(new Date());
        tDeviceType.setUpdateTime(new Date());
        int insert = tDeviceTypeMapper.insert(tDeviceType);
        return insert;
    }

    @Override
    @Transactional
    public int editType(TDeviceType tDeviceType) {
        tDeviceType.setUpdateTime(new Date());
        int i = tDeviceTypeMapper.updateById(tDeviceType);
        return i;
    }
}
